package com.smh.demo1.a01;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * @author shiminghui
 * @date 2025/4/9 17:48
 * @description: TODO
 */
@Component
@Slf4j
public class Component1 {

    @EventListener // 默认同步,可以添加@Async注解,异步处理事件
//    @Async
    public void listen(MyEvent event) throws InterruptedException {
//        System.out.println("Component1监听到事件：" + event.getSource());
        log.debug("Component1监听到事件：" + event.getSource());
        Thread.sleep(1000); // 用于检测监听器是同步处理的还是异步处理的
        log.debug("Component1处理事件结束");
    }

}
